let timeOut = 0;
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {
    extClass: {
      type: String,
      value: ''
    },
    show:{
      type:Boolean,
      value:true
    },
    autoplay:{
      type:Boolean,
      value:true
    },
    list:{
      type:Array,
      value:()=>{
        return []
      },
      observer:function(val){
        console.log(val,'------')
      }
    }
  },

  lifetimes:{

  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUri: getApp().globalData.imgUri,
    cdn: getApp().globalData.cdn,
    // show: true,
    bottomInset: 20,
    swiperIndex: 0,
    swiperDate: [{
        type: 'image',
        url: getApp().globalData.imgUri+'/infoSwiper/info-banner-1.png'
      },
      // {
      //   type: 'video',
      //   url: "https://www.w3school.com.cn/example/html5/mov_bbb.mp4",
      // },
      // {
      //   type: 'image',
      //   url: getApp().globalData.imgUri+'/infoSwiper/info-banner-2.png'
      // }
    ]
  },
  attached() {
    // javascript
    const systemInfo = wx.getWindowInfo();
    const bottomInset = Math.abs(systemInfo.safeArea.bottom - systemInfo.windowHeight);
    this.setData({
      bottomInset
    })


    // console.log('Bottom inset: ', bottomInset);
    // timeOut = setTimeout(() => {
    //   this.nextSwiper();
    // }, 3000)
  },
  /**
   * 组件的方法列表
   */
  methods: {
    goToUrl(e){
      let { index } = e.currentTarget.dataset
      let detail = this.data.list[index]
      console.log(detail)
      if (detail.jumpType == "INNER_APP") { //内部小程序
        wx.navigateTo({
          url: detail.jumpParam,
        });
      } else if (detail.jumpType == "OUT_APP") { //外部小程序
        wx.navigateToMiniProgram({
          appId: detail.jumpAppid,
          path: detail.jumpParam
        });
      } else if (detail.jumpType == "WEB_H5") { //
        wx.navigateTo({
          url: '/shop/webview/webview?webSrc=' + detail.jumpParam,
        })
      }
    },


    swiperChange(e) {
      // clearTimeout(timeOut);
      this.setData({
        swiperIndex: e.detail.current
      })
      // this.videoPause();
      // if (this.data.swiperDate[e.detail.current].type == 'video') {
      //   this.videoPlay();
      // } else {
      //   timeOut = setTimeout(() => {
      //     this.nextSwiper();
      //   }, 3000)
      // }
    },
    videoEnd() {
      console.log(123);
      if (this.data.swiperIndex < this.data.swiperDate.length - 1) {
        this.setData({
          swiperIndex: this.data.swiperIndex + 1
        })

      }
    },
    // 视频播放
    videoPlay() {
      const that = this;
      let videoplay = wx.createVideoContext(`video-${this.data.swiperIndex}`, this); //   创建 video 上下文 VideoContext 对象。
      console.log(videoplay, 222);
      videoplay.play();
      that.setData({
        isPhotoShow: false
      })
      console.log('播放了')
    },
    // 视频暂停
    videoPause() {
      const that = this;
      for (let i = 0; i < this.data.swiperDate.length; i++) {
        if (this.data.swiperDate[i].type == 'video') {
          let videoplay = wx.createVideoContext(`video-${i}`, this); //   创建 video 上下文 VideoContext 对象。
          videoplay.pause();
        }
      }
    },
    hinndeSwiper() {
      this.videoPause();
      this.setData({
        show: false
      })
    },
    nextSwiper() {
      if (this.data.swiperIndex < this.data.swiperDate.length - 1) {
        this.setData({
          swiperIndex: this.data.swiperIndex + 1,
        })
      } else {
        this.setData({
          swiperIndex: 0
        })
      }
    },

  }
})